<#include "/public/macro.html">
<div class="uk-layui-form" style="height: calc(100% - 50px);padding-top:0px;">
	<form class="layui-form" action="/apps/workorders/save.html" method="post" style="width: 100%;height: 100%;" enctype="multipart/form-data" >
		<div class="ukefu-containter">
			<div class="ukefu-col-left">
				<h1 class="site-h1">
					工单基本信息
				</h1>
				<#if models?? && models["contacts"]?? && models["contacts"] == true>
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						联系人
						
					</label>
					<div class="layui-input-block">
						<select id="contacts" name="cusid" lay-ignore class="layui-input layui-unselect" style="width: 100%">
						  
						</select>
					</div>
				</div>
				</#if>

				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						所属单位
					</label>
					<div class="layui-input-block">
						<input type="text" name="cusorgan" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">
						工单发起人
					</label>
					<div class="layui-input-block">
						<select id="initiator" name="initiator" lay-ignore class="layui-input layui-unselect" style="width: 100%">
							<option value="${user.id!''}">${user.username!''}</option>
						 	<#if userList?? && userList.content??>
						 	<#list userList.content as wouser>
						 	<#if wouser.id != user.id>
						 	<option value="${wouser.id!''}">${wouser.username!''}（${wouser.uname!''}）</option>
						 	</#if>
						 	</#list>
						 	</#if> 
						</select>
					</div>
				</div>
				<div class="layui-inline ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">受理部门/受理人</label>
					<div class="layui-input-inline" style="width: 145px;">
						<select lay-ignore class="ukefu-select" name="accdept" id="accdept" style="width: 100%">
							<option value="">请选择部门</option>
						 	<#if organList??>
						 	<#list organList as organ>
						 	<option value="${organ.id!''}">${organ.name!''}</option>
						 	</#list>
						 	</#if> 
						</select>
					</div>
					<div class="layui-input-inline" style="width: 145px;" id="deptuserdiv">
						<#include "/apps/business/workorders/deptuser.html">
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">工单状态</label>
					<div class="layui-input-block">
						<select id="status" name="status" lay-ignore="" class="ukefu-select select2-hidden-accessible" style="width:100%;"  tabindex="-1" aria-hidden="true" >
							<#list uKeFuDic['com.dic.workorders.status'] as macroSysDic>
							<option value="<#if macroSysDic.discode>${macroSysDic.code}<#else>${macroSysDic.id}</#if>">${macroSysDic.name}</option>
							</#list>
						</select>
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">工单类型</label>
					<div class="layui-input-block">
						<select name="wotype" lay-ignore class="ukefu-select" style="width:100%;">
							<#if workOrderTypeList??>
							<#list workOrderTypeList as workOrderType>
								<option value="${workOrderType.id!''}">${workOrderType.name!''}<#if workOrderType.bpm>（流程）</#if></option>
							</#list>
							</#if>
						</select>  
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">优先级</label>
					<div class="layui-input-block">
						<@select "com.dic.workorders.priority" "priority" "" "lay-ignore class=ukefu-select style=width:100%;"/>
					</div>
				</div>
				
				<div class="layui-form-item ukefu-form-item">
					<label class="layui-form-label ukefu-form-label">标签</label>
					<div class="layui-input-block">
						<select lay-ignore name="tags" class="ukefu-select" placeh style="width: 100%" multiple="multiple">
						 	<#if tags??>
						 	<#list tags as tag>
						 	<option value="${tag.id!''}">${tag.tag!''}</option>
						 	</#list>
						 	</#if> 
						</select>
					</div>
				</div>
			</div>
			<div class="ukefu-col-right">
				<h1 class="site-h1">
					工单内容
				</h1>
				<div class="layui-form-item">
					<label class="layui-form-label">工单标题
						<font color="red">*</font>
					</label>
					<div class="layui-input-block ukefu-form-block">
						<input type="text" name="title" autocomplete="off" class="layui-input" required lay-verify="required">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">
						工单内容
						<font color="red">*</font>
					</label>
					<div class="layui-input-block ukefu-form-block">
						<textarea name="content" lay-verify="required" id="content" style="width:100%;height:400px;"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">
						附件
					</label>
					<div class="layui-input-block ukefu-form-block">
						<div class="layui-box layui-upload-button">
							<input type="file" name="files"
								accept="*"
								class="layui-upload-file"
								onchange="$(this).closest('.layui-form-item').append($(this).closest('.ukefu-form-block').prop('outerHTML'));$(this).closest('.ukefu-form-block').find('.file_ad').html($(this).val());$(this).closest('.ukefu-form-block').find('.file_del').show();"><span
								class="layui-upload-icon"><i class="layui-icon">&#xe608;</i>上传附件</span>
						</div>
						<span>
							<span class="file_ad"></span>
							<span class="file_del" style="display:none;">
								<a href="javascript:void(0)" style="margin-left:10px;" onclick="$(this).closest('.ukefu-form-block').remove();">
						  			<i class="layui-icon" style="color:red;">&#x1006;</i>
						  			删除
						  		</a>
							</span>
						</span>
					</div>
				</div>
			</div>
		</div>

		<div class="layui-form-button">
			<div class="layui-button-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo" onclick="editor.sync();">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>

<script>
	layui.use('form', function() {
		var form = layui.form;
		form.render(); //更新全部
	});
	layui.use(['element'], function(){
		var element = layui.element;
	});
	var editor ;
	KindEditor.ready(function(K) {
		editor = K.create('#content', {
			themeType : 'simple',
			width:"100%",
			resizeType:0,
			uploadJson : "/res/image/upload.html",
			items : ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
					 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
					 'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
            allowFileManager : false,
			fontsize:16
		});
	});
	KindEditor.options.cssData = "body { font-size: 15px; font-family:'Microsoft Yahei', 'Helvetica', 'Simsun', 'Arial';}";
	$(document).ready(function() {
		$("#contacts").select2({
			language: 'zh-CN' ,
			placeholder: "请选择联系人",
			ajax: {
				url: "/res/contacts.html",
				dataType: 'json',
				delay: 250,
				processResults: function (data, params) {
					return {
						results: data
					};
				}    
			}
		});
		
		$("#initiator").select2({
			language: 'zh-CN' ,
			placeholder: "请选择发起人",
			ajax: {
				url: "/res/users.html",
				dataType: 'json',
				delay: 250,
				processResults: function (data, params) {
					return {
						results: data
					};
				}    
			}
		});
		
		$(".ukefu-select").select2({minimumResultsForSearch: Infinity});
		$('#accdept').on('select2:select', function (evt) {
			 //选择部门下的 人员
			 loadURL("/apps/workorders/dept/user.html?dept="+evt.target.value , "#deptuserdiv");
		});
	});
</script>